
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/23/2011 03:47:09
-- Generated from EDMX file: C:\Documents and Settings\Administrador\Mis documentos\Visual Studio 2010\Projects\Obligatorio1\Obligatorio1\Modelo\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Obligatorio1];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Direccion_Direccion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Direccion] DROP CONSTRAINT [FK_Direccion_Direccion];
GO
IF OBJECT_ID(N'[dbo].[FK_Direccion_Persona]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Direccion] DROP CONSTRAINT [FK_Direccion_Persona];
GO
IF OBJECT_ID(N'[dbo].[FK_Email_Persona]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Email] DROP CONSTRAINT [FK_Email_Persona];
GO
IF OBJECT_ID(N'[dbo].[FK_Email_Tipo_Email]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Email] DROP CONSTRAINT [FK_Email_Tipo_Email];
GO
IF OBJECT_ID(N'[dbo].[FK_Persona_Grupo_Grupo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Persona_Grupo] DROP CONSTRAINT [FK_Persona_Grupo_Grupo];
GO
IF OBJECT_ID(N'[dbo].[FK_Persona_Grupo_Persona]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Persona_Grupo] DROP CONSTRAINT [FK_Persona_Grupo_Persona];
GO
IF OBJECT_ID(N'[dbo].[FK_Telefono_Persona]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Telefono] DROP CONSTRAINT [FK_Telefono_Persona];
GO
IF OBJECT_ID(N'[dbo].[FK_Telefono_Tipos_Telefono]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Telefono] DROP CONSTRAINT [FK_Telefono_Tipos_Telefono];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Direccion]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Direccion];
GO
IF OBJECT_ID(N'[dbo].[Email]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Email];
GO
IF OBJECT_ID(N'[dbo].[Grupo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Grupo];
GO
IF OBJECT_ID(N'[dbo].[Persona]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Persona];
GO
IF OBJECT_ID(N'[dbo].[Persona_Grupo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Persona_Grupo];
GO
IF OBJECT_ID(N'[dbo].[sysdiagrams]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysdiagrams];
GO
IF OBJECT_ID(N'[dbo].[Telefono]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Telefono];
GO
IF OBJECT_ID(N'[dbo].[TiposDireccion]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TiposDireccion];
GO
IF OBJECT_ID(N'[dbo].[TiposEmail]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TiposEmail];
GO
IF OBJECT_ID(N'[dbo].[TiposTelefono]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TiposTelefono];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Direccion'
CREATE TABLE [dbo].[Direccion] (
    [direccion] varchar(50)  NOT NULL,
    [ciudad] varchar(50)  NOT NULL,
    [codigoPostal] int  NULL,
    [pais] varchar(50)  NOT NULL,
    [tipo] varchar(50)  NOT NULL,
    [idPersona] int  NOT NULL
);
GO

-- Creating table 'Email'
CREATE TABLE [dbo].[Email] (
    [idPersona] int  NOT NULL,
    [email] varchar(50)  NOT NULL,
    [tipo] varchar(50)  NULL
);
GO

-- Creating table 'Grupo'
CREATE TABLE [dbo].[Grupo] (
    [nombre] varchar(50)  NOT NULL
);
GO

-- Creating table 'Persona'
CREATE TABLE [dbo].[Persona] (
    [nombre] varchar(50)  NOT NULL,
    [apellido] varchar(50)  NOT NULL,
    [fechaNacimiento] datetime  NOT NULL,
    [id] int IDENTITY(1,1) NOT NULL,
    [comentario] varchar(150)  NULL,
    [foto] varbinary(max)  NULL
);
GO

-- Creating table 'sysdiagrams'
CREATE TABLE [dbo].[sysdiagrams] (
    [name] nvarchar(128)  NOT NULL,
    [principal_id] int  NOT NULL,
    [diagram_id] int IDENTITY(1,1) NOT NULL,
    [version] int  NULL,
    [definition] varbinary(max)  NULL
);
GO

-- Creating table 'Telefono'
CREATE TABLE [dbo].[Telefono] (
    [numero] varchar(50)  NOT NULL,
    [tipo] varchar(50)  NOT NULL,
    [idPersona] int  NOT NULL
);
GO

-- Creating table 'TiposDireccion'
CREATE TABLE [dbo].[TiposDireccion] (
    [nombre] varchar(50)  NOT NULL
);
GO

-- Creating table 'TiposEmail'
CREATE TABLE [dbo].[TiposEmail] (
    [nombre] varchar(50)  NOT NULL
);
GO

-- Creating table 'TiposTelefono'
CREATE TABLE [dbo].[TiposTelefono] (
    [nombre] varchar(50)  NOT NULL
);
GO

-- Creating table 'Persona_Grupo'
CREATE TABLE [dbo].[Persona_Grupo] (
    [Grupo_nombre] varchar(50)  NOT NULL,
    [Persona_id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [direccion], [ciudad], [pais], [idPersona] in table 'Direccion'
ALTER TABLE [dbo].[Direccion]
ADD CONSTRAINT [PK_Direccion]
    PRIMARY KEY CLUSTERED ([direccion], [ciudad], [pais], [idPersona] ASC);
GO

-- Creating primary key on [email] in table 'Email'
ALTER TABLE [dbo].[Email]
ADD CONSTRAINT [PK_Email]
    PRIMARY KEY CLUSTERED ([email] ASC);
GO

-- Creating primary key on [nombre] in table 'Grupo'
ALTER TABLE [dbo].[Grupo]
ADD CONSTRAINT [PK_Grupo]
    PRIMARY KEY CLUSTERED ([nombre] ASC);
GO

-- Creating primary key on [id] in table 'Persona'
ALTER TABLE [dbo].[Persona]
ADD CONSTRAINT [PK_Persona]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [diagram_id] in table 'sysdiagrams'
ALTER TABLE [dbo].[sysdiagrams]
ADD CONSTRAINT [PK_sysdiagrams]
    PRIMARY KEY CLUSTERED ([diagram_id] ASC);
GO

-- Creating primary key on [numero], [idPersona] in table 'Telefono'
ALTER TABLE [dbo].[Telefono]
ADD CONSTRAINT [PK_Telefono]
    PRIMARY KEY CLUSTERED ([numero], [idPersona] ASC);
GO

-- Creating primary key on [nombre] in table 'TiposDireccion'
ALTER TABLE [dbo].[TiposDireccion]
ADD CONSTRAINT [PK_TiposDireccion]
    PRIMARY KEY CLUSTERED ([nombre] ASC);
GO

-- Creating primary key on [nombre] in table 'TiposEmail'
ALTER TABLE [dbo].[TiposEmail]
ADD CONSTRAINT [PK_TiposEmail]
    PRIMARY KEY CLUSTERED ([nombre] ASC);
GO

-- Creating primary key on [nombre] in table 'TiposTelefono'
ALTER TABLE [dbo].[TiposTelefono]
ADD CONSTRAINT [PK_TiposTelefono]
    PRIMARY KEY CLUSTERED ([nombre] ASC);
GO

-- Creating primary key on [Grupo_nombre], [Persona_id] in table 'Persona_Grupo'
ALTER TABLE [dbo].[Persona_Grupo]
ADD CONSTRAINT [PK_Persona_Grupo]
    PRIMARY KEY NONCLUSTERED ([Grupo_nombre], [Persona_id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [tipo] in table 'Direccion'
ALTER TABLE [dbo].[Direccion]
ADD CONSTRAINT [FK_Direccion_Direccion]
    FOREIGN KEY ([tipo])
    REFERENCES [dbo].[TiposDireccion]
        ([nombre])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Direccion_Direccion'
CREATE INDEX [IX_FK_Direccion_Direccion]
ON [dbo].[Direccion]
    ([tipo]);
GO

-- Creating foreign key on [idPersona] in table 'Direccion'
ALTER TABLE [dbo].[Direccion]
ADD CONSTRAINT [FK_Direccion_Persona]
    FOREIGN KEY ([idPersona])
    REFERENCES [dbo].[Persona]
        ([id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Direccion_Persona'
CREATE INDEX [IX_FK_Direccion_Persona]
ON [dbo].[Direccion]
    ([idPersona]);
GO

-- Creating foreign key on [idPersona] in table 'Email'
ALTER TABLE [dbo].[Email]
ADD CONSTRAINT [FK_Email_Persona]
    FOREIGN KEY ([idPersona])
    REFERENCES [dbo].[Persona]
        ([id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Email_Persona'
CREATE INDEX [IX_FK_Email_Persona]
ON [dbo].[Email]
    ([idPersona]);
GO

-- Creating foreign key on [tipo] in table 'Email'
ALTER TABLE [dbo].[Email]
ADD CONSTRAINT [FK_Email_Tipo_Email]
    FOREIGN KEY ([tipo])
    REFERENCES [dbo].[TiposEmail]
        ([nombre])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Email_Tipo_Email'
CREATE INDEX [IX_FK_Email_Tipo_Email]
ON [dbo].[Email]
    ([tipo]);
GO

-- Creating foreign key on [idPersona] in table 'Telefono'
ALTER TABLE [dbo].[Telefono]
ADD CONSTRAINT [FK_Telefono_Persona]
    FOREIGN KEY ([idPersona])
    REFERENCES [dbo].[Persona]
        ([id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Telefono_Persona'
CREATE INDEX [IX_FK_Telefono_Persona]
ON [dbo].[Telefono]
    ([idPersona]);
GO

-- Creating foreign key on [tipo] in table 'Telefono'
ALTER TABLE [dbo].[Telefono]
ADD CONSTRAINT [FK_Telefono_Tipos_Telefono]
    FOREIGN KEY ([tipo])
    REFERENCES [dbo].[TiposTelefono]
        ([nombre])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Telefono_Tipos_Telefono'
CREATE INDEX [IX_FK_Telefono_Tipos_Telefono]
ON [dbo].[Telefono]
    ([tipo]);
GO

-- Creating foreign key on [Grupo_nombre] in table 'Persona_Grupo'
ALTER TABLE [dbo].[Persona_Grupo]
ADD CONSTRAINT [FK_Persona_Grupo_Grupo]
    FOREIGN KEY ([Grupo_nombre])
    REFERENCES [dbo].[Grupo]
        ([nombre])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Persona_id] in table 'Persona_Grupo'
ALTER TABLE [dbo].[Persona_Grupo]
ADD CONSTRAINT [FK_Persona_Grupo_Persona]
    FOREIGN KEY ([Persona_id])
    REFERENCES [dbo].[Persona]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Persona_Grupo_Persona'
CREATE INDEX [IX_FK_Persona_Grupo_Persona]
ON [dbo].[Persona_Grupo]
    ([Persona_id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------